package com.googlecode.dbtesting;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 * Provides the classes necessary to create ...
 * <p/>
 * <p/>
 * Author: Ruslan
 * Date: 22.02.2008
 * License: GPL v3
 */

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {

            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();

//            sessionFactory = new AnnotationConfiguration()
//                    .addAnnotatedClass(BasicDTO.class)
//                    .addAnnotatedClass(UserDTO.class)
//                    .configure()
//                    .buildSessionFactory();

        } catch (Exception e) {
            e.printStackTrace();
            throw new ExceptionInInitializerError(e);
        }
    }

    public static Session getSession()
            throws HibernateException {
        return sessionFactory.openSession();
    }

}

